/* eslint-disable*/
import { REDUX_TYPE_ENUM } from '@CONSTANTS/app'
import { RequestTypesITF } from '@REDUXITF/index'

export default function createReducer(initState: any, handlers: any) {
  return function reducer(state = initState, action: any) {
    const handler = handlers[action.type]
    return handler ? handler(state, action) : state
  }
}

export function createRequestTypes(base: string): RequestTypesITF {
  return [REDUX_TYPE_ENUM.REQUEST, REDUX_TYPE_ENUM.SUCCESS, REDUX_TYPE_ENUM.FAILURE].reduce((acc: any, type) => {
    acc[type] = `${base}_${type}`
    return acc
  }, {})
}
